<?php

class PaymentCreateWidget extends CWidget {

    public $visible = true;

    public function init() {
        
    }

    public function run() {
        if ($this->visible) {
            $this->renderContent();
        }
    }

    protected function renderContent() {
        $model = new PaymentMethod;
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'paymentmethod-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
        if (isset($_POST['PaymentMethod'])) {
            $model = new PaymentMethod;
            $model->attributes = $_POST['PaymentMethod'];
            if ($model->save()) {
                user()->setFlash('success', t('cms', 'Create Successfully!'));
            }
        }
        $this->render('cmswidgets.views.shopping.payment_create_widget', array('model' => $model));
    }

}
